<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        .box {
            width: 3900px;
            height: 500px;
            border: 1px solid #000;
            margin: 50px auto;
            overflow: hidden;
        }
        .box ul {
            list-style: none;
            /* 设置大一点，这样li才能浮动 */
            width: 13000px;
            position: relative;
        }
        .box ul li {
            float: left;
            margin-right: 20px;
        }
    </style>
</head>

<body>
    <div id="box" class="box">
        <ul id="list">
            <li><img src="image/1.jpg" alt=""></li>
            <li><img src="image/2.jpg" alt=""></li>
            <li><img src="image/3.jpg" alt=""></li>
            <li><img src="image/4.jpg" alt=""></li>
            <li><img src="image/5.jpg" alt=""></li>
            <li><img src="image/6.jpg" alt=""></li>
        </ul>
    </div>
    <script>
        var box = document.getElementById('box');
        var list = document.getElementById('list');

        // 复制多一遍所有的li
        list.innerHTML += list.innerHTML;

        // 全局变量，表示当前list的left值
        var left = 0;

        // 定时器  全局变量
        var timer;
        
        move();
        // 动画封装成函数 一开始也调用move
        function move() {
            // 设表先关，防止动画累积
            clearInterval(timer);

            timer = setInterval(function() {
            left -= 4;
            // 验收
            if (left <= -6000) {
                left = 0;
            }
            list.style.left = left + 'px';
        }, 1);

        }
        // 鼠标进入停止定时器
        box.onmouseenter = function()  {
            clearInterval(timer);
        }

        // 鼠标离开继续定时器
        box.onmouseleave = function() {
            move();
        }
    </script>
</body>

</html>